import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({

  state: {
    schoolId:'',
    schooluser:JSON.parse(window.localStorage.getItem('access-schooluser')),
    schoolname: '',
    treeTable: []
  },
  mutations: {
    setSchoolId(state,id){
      state.schoolId= id;
    },
    setSchoolname(state,name){
      state.schoolname = name;
    },
    setTreeTable(state,treeData){
      function getTreeList(root, id, list){
        // 拿到一级
        for(let item of root){
          if(item.evaluateindex1name){
            list.push(item)
          }
        }
        // 拿到二级
        for(let i of list){
          i.children=[] //给一级加上children
          i.label = i.evaluateindex1name
          delete i.evaluateindex1name
          for(let item of root){
            if (item.evaluateindex2name&&item.evaluateindex1id==i.evaluateindex1id){
              i.children.push(item)
            }
          }
        }
        // 拿到三级
        for(let i of list){
          for (let u of i.children){
            u.children=[]
            u.label = u.evaluateindex2name
            delete u.evaluateindex2name
            for(let item of root){
              if (item.evaluateindex3name&&item.evaluateindex2id==u.evaluateindex2id){
                item.success = false
                item.expertsuccess=false
                u.children.push(item)
              }
            }
            for(let v of u.children){
              v.label=v.evaluateindex3name
              delete v.evaluateindex3name
            }
          }
        }
        return list
      }
      state.treeTable = getTreeList(treeData,null,[])
    },
    setSu(state,label){
      // const a =state.treeTable.getNode(label)
    //   const a = breadthQuery(state.treeTable, label)
    //   function breadthQuery(tree, label) {
    //     var stark = [];
    //     stark = stark.concat(tree);
    //     while(stark.length) {
    //       var temp = stark.shift();
    //       if(temp.children) {
    //         stark = stark.concat(temp.children);
    //       }
    //       if(temp.label === label) {
    //         return temp;
    //       }
    //     }
    //   }
    //
    //   a.data.success =true
    }
  },
  actions: {
  },
  modules: {
  }
})
